<?php

require_once ('Zend/Form.php');
require_once ('Zend/Translate.php');

class CoreForm extends Zend_Form {
	
	protected $translator;
	protected $_api;
	
	protected function getMessageTranslator() {
		$page = 'message';
		$english = array ('stringLengthTooShort' => $this->translator->t ( 'stringLengthTooShort', $page ), 'stringLengthTooLong' => $this->translator->t ( 'stringLengthTooLong', $page ), 'regexNotMatch' => $this->translator->t ( 'regexNotMatch', $page ), 'isEmpty' => $this->translator->t ( 'isEmpty', $page ), 'emailAddressInvalid' => $this->translator->t ( 'emailAddressInvalid', $page ), 'emailAddressInvalidHostname' => $this->translator->t ( 'emailAddressInvalidHostname', $page ), 'missingValue' => $this->translator->t ( 'missingValue', $page ), 'badCaptcha' => $this->translator->t ( 'badCaptcha', $page ) );
		
		$translate = new Zend_Translate ( 'array', $english/*, 'en' ,$options*/);
		return $translate;
	}
	
	protected function setTdCheckboxDecorators($element, $class = "checkbox-td") {
		$element->setDecorators ( array ('ViewHelper', 'Description', 'Errors', array ('Label', array ('placement' => 'APPEND' ) ), array (array ('data' => 'HtmlTag' ), array ('tag' => 'td', 'colspan' => '2', 'class' => $class ) ), array (array ('row' => 'HtmlTag' ), array ('tag' => 'tr' ) ) ) );
	}
	
	protected function setTdDecorators($element, $needStar = false, $rowAttrs = null) {
		$rowAttr = array ('tag' => 'tr' );
		
		if (is_array ( $rowAttrs )) {
			foreach ( $rowAttrs as $key => $val ) {
				$rowAttr [$key] = $val;
			}
		}
		
		if ($needStar) {
			
			if ($needStar === 2) {
				$StarDecorator = 'StarDecoratorForState';
			} else {
				if ($needStar === 3) {
					$StarDecorator = 'StarDecoratorForStateInvisible';
				} else {
					$StarDecorator = 'StarDecorator';
				}
			}
			
			$element->setDecorators ( array ('ViewHelper', $StarDecorator, 'Description', 'Errors', array (array ('data' => 'HtmlTag' ), array ('tag' => 'td', 'class' => 'right-td' ) ), array ('Label', array ('tag' => 'td' ) ), array (array ('row' => 'HtmlTag' ), $rowAttr ) ) );
		} else {
			$element->setDecorators ( array ('ViewHelper', 'Description', 'Errors', array (array ('data' => 'HtmlTag' ), array ('tag' => 'td' ) ), array ('Label', array ('tag' => 'td' ) ), array (array ('row' => 'HtmlTag' ), $rowAttr ) ) );
		}
		return $element;
	}
	
	protected function getEmailMessages() {
		$messages = array ();
		$messages [Zend_Validate_EmailAddress::INVALID_FORMAT] = $this->translator->t ( 'emailAddressInvalid', 'message' );
		$messages [Zend_Validate_Hostname::INVALID_HOSTNAME] = $this->translator->t ( 'hostnameInvalidHostname', 'message' );
		$messages [Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED] = $this->translator->t ( 'hostnameLocalNameNotAllowed', 'message' );
		$messages [Zend_Validate_Hostname::UNKNOWN_TLD] = $this->translator->t ( 'hostnameUnknownTld', 'message' );
		$messages [Zend_Validate_Hostname::UNDECIPHERABLE_TLD] = $this->translator->t ( 'hostnameUndecipherableTld', 'message' );
		$messages [Zend_Validate_Hostname::INVALID_LOCAL_NAME] = $this->translator->t ( 'hostnameInvalidLocalName', 'message' );
		
		return $messages;
	}
	
	function __construct($options = null, $translator = null) {
		parent::__construct ( $options );
		
		$this->translator = $translator;
		$this->setTranslator ( $this->getMessageTranslator () );
		$this->_api = Zend_Registry::get ( 'api' );
	
	}
}

?>